import java.nio.channels.Selector;
import java.util.Iterator;

//: innerclasses/Sequence.java
// Holds a sequence of Objects.

public class E09_Sequence {
	private Object[] items;
	private int next = 0;

	public E09_Sequence(int size) {
		items = new Object[size];
	}

	public void add(Object x) {
		if (next < items.length)
			items[next++] = x;
	}

	private class SequenceSelector implements Iterator<Object> {

		int i = 0;

		@Override
		public boolean hasNext() {
			return i + 1 < items.length;
		}

		@Override
		public Object next() {
			return items[++i];
		}

		@Override
		public void remove() {
			throw new UnsupportedOperationException();
		}

	}

	public Iterator<Object> iterator() {
		return new SequenceSelector();
	}

	public static void main(String[] args) {
		E09_Sequence sequence = new E09_Sequence(10);
		for (int i = 0; i < 10; i++)
			sequence.add(Integer.toString(i));
		Iterator iterator = sequence.iterator();
		while (iterator.hasNext()) {
			iterator.next();
			System.out.print(iterator.toString() + " ");

		}
	}

}